public class code4 {
    public int minNumberOfFrogs(String ch) {
        char[] croakOfFrogs = ch.toCharArray();
        int[] hash = new int[128];//记录字母对应的个数，数字模拟哈希表
        for(char c:croakOfFrogs) {
            hash[c]++;
            if(c =='c') {
                if(hash['k']>0) hash['k']--;
            } else if(c =='r') {
                if(hash['c']==0) return -1;
                hash['c']--;
            } else if(c =='o') {
                if(hash['r']==0) return -1;
                hash['r']--;
            } else if(c =='a') {
                if(hash['o']==0) return -1;
                hash['o']--;
            } else if(c=='k') {
                if(hash['a']==0) return -1;
                hash['a']--;
            }
        }
        int ret = hash['c']+hash['r']+hash['o']+hash['a'];
        return ret>0?-1:hash['k'];
    }
}
